package com.ruoyi.web.controller.lwpq;

import java.util.List;

import com.ruoyi.lwpq.domain.LwpqYggl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lwpq.domain.LwpqLwpq;
import com.ruoyi.lwpq.service.ILwpqLwpqService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 劳务派遣Controller
 * 
 * @author ruoyi
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/lwpq/lwpq")
public class LwpqLwpqController extends BaseController
{
    private String prefix = "lwpq/lwpq";

    @Autowired
    private ILwpqLwpqService lwpqLwpqService;

    @RequiresPermissions("lwpq:lwpq:view")
    @GetMapping()
    public String lwpq()
    {
        return prefix + "/lwpq";
    }

    /**
     * 查询劳务派遣列表
     */
    @RequiresPermissions("lwpq:lwpq:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LwpqLwpq lwpqLwpq)
    {
        startPage();
        lwpqLwpq.setCreateBy(getLoginName());
        List<LwpqLwpq> list = lwpqLwpqService.selectLwpqLwpqList(lwpqLwpq);
        return getDataTable(list);
    }

    /**
     * 导出劳务派遣列表
     */
    @RequiresPermissions("lwpq:lwpq:export")
    @Log(title = "劳务派遣", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LwpqLwpq lwpqLwpq)
    {
        List<LwpqLwpq> list = lwpqLwpqService.selectLwpqLwpqList(lwpqLwpq);
        ExcelUtil<LwpqLwpq> util = new ExcelUtil<LwpqLwpq>(LwpqLwpq.class);
        return util.exportExcel(list, "劳务派遣数据");
    }

    /**
     * 新增劳务派遣
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存劳务派遣
     */
    @RequiresPermissions("lwpq:lwpq:add")
    @Log(title = "劳务派遣", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LwpqLwpq lwpqLwpq)
    {
        lwpqLwpq.setCreateBy(getLoginName());
        return toAjax(lwpqLwpqService.insertLwpqLwpq(lwpqLwpq));
    }

    /**
     * 修改劳务派遣
     */
    @RequiresPermissions("lwpq:lwpq:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LwpqLwpq lwpqLwpq = lwpqLwpqService.selectLwpqLwpqById(id);
        mmap.put("lwpqLwpq", lwpqLwpq);
        return prefix + "/edit";
    }

    /**
     * 修改保存劳务派遣
     */
    @RequiresPermissions("lwpq:lwpq:edit")
    @Log(title = "劳务派遣", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LwpqLwpq lwpqLwpq)
    {
        lwpqLwpq.setUpdateBy(getLoginName());
        return toAjax(lwpqLwpqService.updateLwpqLwpq(lwpqLwpq));
    }

    /**
     * 删除劳务派遣
     */
    @RequiresPermissions("lwpq:lwpq:remove")
    @Log(title = "劳务派遣", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lwpqLwpqService.deleteLwpqLwpqByIds(ids));
    }

    @RequiresPermissions("lwpq:lwpq:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<LwpqLwpq> util = new ExcelUtil<LwpqLwpq>(LwpqLwpq.class);
        List<LwpqLwpq> lwpq = util.importExcel(file.getInputStream());
        String message = lwpqLwpqService.importLwpq(lwpq, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }

    @RequiresPermissions("lwpq:lwpq:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<LwpqLwpq> util = new ExcelUtil<LwpqLwpq>(LwpqLwpq.class);
        return util.importTemplateExcel("劳务派遣数据");
    }
}
